package so.shanku.essential.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import aym.util.json.JsonMap;
import so.shanku.essential.R;
import so.shanku.essential.getdata.JsonKeys;

import java.util.List;
import java.util.Map;

/**
 * Created by admin on 15/10/19.
 */
public class ProductParamsAdapter extends MyBaseAdapter {
    private int checkedPosition;//默认选中想

    public int getCheckedPosition() {
        return checkedPosition;
    }

    public void setCheckedPosition(int checkedPosition) {
        this.checkedPosition = checkedPosition;
    }

    public ProductParamsAdapter(Context context) {
        super(context);
    }

    public ProductParamsAdapter(Context context, List<? extends Map<String, ?>> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        GoodsParamsAdapterViewHolder goodsParamsAdapterViewHolder;
        JsonMap jsonMap = (JsonMap) datas.get(i);
        if (view == null) {
            goodsParamsAdapterViewHolder = new GoodsParamsAdapterViewHolder();
            view = View.inflate(context, R.layout.select_goods_params_item, null);
            view.setTag(goodsParamsAdapterViewHolder);
            goodsParamsAdapterViewHolder.textView = (TextView) view;
        } else {
            goodsParamsAdapterViewHolder = (GoodsParamsAdapterViewHolder) view.getTag();
        }
        goodsParamsAdapterViewHolder.textView.setText(jsonMap.getStringNoNull(JsonKeys.Key_ObjName));
        if (jsonMap.getBoolean("IsChecked")) {
            goodsParamsAdapterViewHolder.textView.setSelected(true);
            checkedPosition = i;
        } else {
            goodsParamsAdapterViewHolder.textView.setSelected(false);
        }
        return view;

    }

    class GoodsParamsAdapterViewHolder {
        TextView textView;
    }
}
